import 'package:flutter_app/Util/Object++.dart';
import 'package:flutter_yfree/YFree.dart';
import 'package:flutter_yfree/main/YFree+Model.dart';

class CartListModel {
  late int count_carts;
  late List<CartMainModel> items_carts;

  CartListModel.fromJson(Map<dynamic, dynamic> map) {
    count_carts = map.byInt("count_carts", defaultValue: 0)!;
    items_carts = map.byList("items_carts", (rawValue) => CartMainModel.fromJson(rawValue), defaultValue: [])!;
  }
}

class CartMainModel {
  late String spu;
  late String sku;
  late String titleProduct;
  late String titleType;
  late String img;
  late String money;
  late int countLeft;

  bool isSelect = false;
  int count_input = 1;

  CartMainModel.fromJson(Map<dynamic, dynamic> map) {
    spu = map.byString("spu", defaultValue: "")!;
    sku = map.byString("sku", defaultValue: "")!;
    titleProduct = map.byString("titleProduct", defaultValue: "")!;
    titleType = map.byString("titleType", defaultValue: "")!;
    img = map.byString("img", defaultValue: "")!;
    money = (map.byDouble("money", defaultValue: 0)!).toYuan();
    countLeft = map.byInt("countLeft", defaultValue: 0)!;
  }

  String toJson() => yToJson({
        "spu": spu,
        "sku": sku,
        "count_input": count_input,
      });
}
